package com.itboy.mall.pms.skusaleattrvalue.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.pms.skusaleattrvalue.vo.MallSkuSaleAttrValueVo;
import com.itboy.mall.pms.skusaleattrvalue.bo.MallSkuSaleAttrValueQueryBo;
import com.itboy.mall.pms.skusaleattrvalue.bo.MallSkuSaleAttrValueAddBo;
import com.itboy.mall.pms.skusaleattrvalue.bo.MallSkuSaleAttrValueEditBo;
import com.itboy.mall.pms.skusaleattrvalue.service.IMallSkuSaleAttrValueService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * sku销售属性&值Controller
 *
 * @author itboy
 * @date 2021-08-08
 */
@Validated
@Api(value = "sku销售属性&值控制器", tags = {"sku销售属性&值管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/skuSaleAttrValue")
public class MallSkuSaleAttrValueController extends BaseController {

    private final IMallSkuSaleAttrValueService iMallSkuSaleAttrValueService;

    /**
     * 查询sku销售属性&值列表
     */
    @ApiOperation("查询sku销售属性&值列表")
    @PreAuthorize("@ss.hasPermi('mall:skuSaleAttrValue:list')")
    @GetMapping("/list")
    public TableDataInfo<MallSkuSaleAttrValueVo> list(@Validated MallSkuSaleAttrValueQueryBo bo) {
        return iMallSkuSaleAttrValueService.queryPageList(bo);
    }

    /**
     * 导出sku销售属性&值列表
     */
    @ApiOperation("导出sku销售属性&值列表")
    @PreAuthorize("@ss.hasPermi('mall:skuSaleAttrValue:export')")
    @Log(title = "sku销售属性&值", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallSkuSaleAttrValueVo> export(@Validated MallSkuSaleAttrValueQueryBo bo) {
        List<MallSkuSaleAttrValueVo> list = iMallSkuSaleAttrValueService.queryList(bo);
        ExcelUtil<MallSkuSaleAttrValueVo> util = new ExcelUtil<MallSkuSaleAttrValueVo>(MallSkuSaleAttrValueVo.class);
        return util.exportExcel(list, "sku销售属性&值");
    }

    /**
     * 获取sku销售属性&值详细信息
     */
    @ApiOperation("获取sku销售属性&值详细信息")
    @PreAuthorize("@ss.hasPermi('mall:skuSaleAttrValue:query')")
    @GetMapping("/{id}")
    public AjaxResult<MallSkuSaleAttrValueVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iMallSkuSaleAttrValueService.queryById(id));
    }

    /**
     * 新增sku销售属性&值
     */
    @ApiOperation("新增sku销售属性&值")
    @PreAuthorize("@ss.hasPermi('mall:skuSaleAttrValue:add')")
    @Log(title = "sku销售属性&值", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallSkuSaleAttrValueAddBo bo) {
        return toAjax(iMallSkuSaleAttrValueService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改sku销售属性&值
     */
    @ApiOperation("修改sku销售属性&值")
    @PreAuthorize("@ss.hasPermi('mall:skuSaleAttrValue:edit')")
    @Log(title = "sku销售属性&值", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallSkuSaleAttrValueEditBo bo) {
        return toAjax(iMallSkuSaleAttrValueService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除sku销售属性&值
     */
    @ApiOperation("删除sku销售属性&值")
    @PreAuthorize("@ss.hasPermi('mall:skuSaleAttrValue:remove')")
    @Log(title = "sku销售属性&值" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iMallSkuSaleAttrValueService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
